<template>
  <div class="monitoring-bit-echart">
    <div class="title">流程分类统计 </div>
    <div ref="$echart" class="chart"></div>
  </div>
</template>

<script>
  import { defineComponent, onMounted, nextTick, ref } from 'vue';
  import * as echarts from 'echarts';

  export default defineComponent({
    name: 'EchartBitView',
    components: {},
    props: {
      echartData: {
        type: Object,
        default: () => {
          return {};
        },
      },
    },
    setup(props) {
      const $echart = ref();
      const initChart = () => {
        var myChart = echarts.init($echart.value);
        var option = {
          color: [
            '#5470c6',
            '#91cc75',
            '#fac858',
            '#ee6666',
            '#73c0de',
            '#3ba272',
            '#fc8452',
            '#9a60b4',
            '#ea7ccc',
          ],
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow',
            },
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true,
          },
          xAxis: [
            {
              type: 'category',
              data: props.echartData.xAxisData,
              axisTick: {
                alignWithLabel: true,
              },
            },
          ],
          yAxis: [
            {
              type: 'value',
            },
          ],
          series: [
            {
              label: {
                show: true,
                position: 'top',
              },
              name: '数量',
              type: 'bar',
              barWidth: '60%',
              data: props.echartData.data,
              colorBy: 'data',
            },
          ],
        };

        option && myChart.setOption(option);
      };
      onMounted(() => {
        nextTick(() => {
          initChart();
        });
      });

      return { $echart };
    },
  });
</script>
<style lang="less" scoped>
  .monitoring-bit-echart {
    height: 100%;
    .title {
      height: 40px;
      height: 40px;
      line-height: 40px;
      font-size: 16px;
      padding-left: 20px;
      font-weight: bold;
    }
    .chart {
      height: 350px;
    }
  }
</style>
